<?php
class pettycashcontroller extends CI_Controller{
	function __construct(){
		parent::__construct();
		$this->load->helper('form');
		$this->load->library('form_validation');
		$this->load->model('pettycash_model');
		$this->load->library('pagination_editable');
	}
	
	function index()
	{      
		$config = array();
		$config['per_page'] = 10;
		$config['first_tag_open'] = '<li>';
		$config['first_tag_close'] = '</li>';
		$config['curr_class'] = 'active';
		$config['full_tag_open'] = '<ul id="pagination-flickr">';
		$config['full_tag_close'] = '</ul>';
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['next_link'] = 'Next &gt;&gt;';
		$config['prev_link'] = '&lt;&lt; Previous';
		$config['next_tag_open'] = '<li class="next">';
		$config['next_tag_close'] = '</li>';
		$config['prev_tag_open'] = '<li class="previous-off">';
		$config['prev_tag_close'] = '</li>';
		
		$config["uri_segment"] = 3;
		$config["base_url"] = site_url('pettycashcontroller/index');
		$config['total_rows'] = $this->pettycash_model->countGetList();
		
		$this->pagination_editable->initialize($config);
	
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		
		if (isset($_POST['btnview'])) 
		{
			if($_POST['kdpettyview'] == "0")
			{         
				$dataprofile = array(
					'page_title' => 'Master > Petty Cash',
					'name' => $this->session->userdata('fullname'),
					'kodepetty' => $this->pettycash_model->getpettyCode(),
					'masterpetty' => $this->pettycash_model->getListlimit($config['per_page'],$page),
					'links' => $this->pagination_editable->create_links(),
					'message' => ''				
				);		
			}
			else if($_POST['kdpettyview'] == "1")
			{
				$this->pettycash_model->setKodepettycash($_POST['pettyview']);
				$dataprofile = array(
					'page_title' => 'Master > Petty Cash',
					'name' => $this->session->userdata('fullname'),
					'kodepetty' => $this->pettycash_model->getpettyCode(),
					'masterpetty' => $this->pettycash_model->getkdpetty(),
					'links' => $this->pagination_editable->create_links(),
					'message' => ''			
				);
			}
			else if($_POST['kdpettyview'] == "2")
			{
				$this->pettycash_model->setnamapettycash($_POST['pettyview']);
				$dataprofile = array(
					'page_title' => 'Master > Petty Cash',
					'name' => $this->session->userdata('fullname'),
					'kodepetty' => $this->pettycash_model->getpettyCode(),
					'masterpetty' => $this->pettycash_model->getnamapetty(),
					'links' => $this->pagination_editable->create_links(),
					'message' => ''			
				);
			}
		}
		else
		{
			$dataprofile = array(
					'page_title' => 'Master > Petty Cash',
					'name' => $this->session->userdata('fullname'),
					'kodepetty' => $this->pettycash_model->getpettyCode(),
					'masterpetty' => $this->pettycash_model->getListlimit($config['per_page'],$page),
					'links' => $this->pagination_editable->create_links(),
					'message' => ''		
			);
			
		}
		$content = array(
			'content' => 'master/petty_cash/viewpettycash'
		);
		$this->template->load('templates/default',$content,$dataprofile);
	}
	
    function getmasterpetty() {
		$config = array();
		$config['per_page'] = 1;
		$config['first_tag_open'] = '<li>';
		$config['first_tag_close'] = '</li>';
		$config['curr_class'] = 'active';
		$config['full_tag_open'] = '<ul id="pagination-flickr">';
		$config['full_tag_close'] = '</ul>';
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['next_link'] = 'Next &gt;&gt;';
		$config['prev_link'] = '&lt;&lt; Previous';
		$config['next_tag_open'] = '<li class="next">';
		$config['next_tag_close'] = '</li>';
		$config['prev_tag_open'] = '<li class="previous-off">';
		$config['prev_tag_close'] = '</li>';
		
		$config["uri_segment"] = 3;
		$config["base_url"] = site_url('pettycashcontroller/index');
		$config['total_rows'] = $this->pettycash_model->countGetList();
		
		$this->pagination_editable->initialize($config);
	
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		
		$idkdpetty = $this->uri->segment(3);
		$this->pettycash_model->setKodepettycash($idkdpetty);

        $dataprofile = array(
            'page_title' => 'Master > Petty Cash',
			'name' => $this->session->userdata('fullname'),
			'kodepetty' => $this->pettycash_model->getpettyCode(),
			'masterpetty' => $this->pettycash_model->getListlimit($config['per_page'],$page),
			'links' => $this->pagination_editable->create_links(),
			'message' => ''	
            /*'individulist' => $this->Individu_model->getOneSelect(),
            'wilayahlist' => $this->Wilayah_model->getWilayahList(),
            'status_nikah' => $this->Statusnikah_model->getStatusNikahList(),
            'foto' => $this->Individu_model->get_images(),
            'role' => $this->session->userdata('role')*/
        );
        $content = array(
            'content' => 'master/petty_cash/viewpettycash'
        );
        $this->template->load('templates/default', $content, $dataprofile);
    }
	
	function tambahmasterpetty() {
		$config = array();
		$config['per_page'] = 10;
		$config['first_tag_open'] = '<li>';
		$config['first_tag_close'] = '</li>';
		$config['curr_class'] = 'active';
		$config['full_tag_open'] = '<ul id="pagination-flickr">';
		$config['full_tag_close'] = '</ul>';
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		$config['next_link'] = 'Next &gt;&gt;';
		$config['prev_link'] = '&lt;&lt; Previous';
		$config['next_tag_open'] = '<li class="next">';
		$config['next_tag_close'] = '</li>';
		$config['prev_tag_open'] = '<li class="previous-off">';
		$config['prev_tag_close'] = '</li>';
		
		$config["uri_segment"] = 3;
		$config["base_url"] = site_url('pettycashcontroller/index');
		$config['total_rows'] = $this->pettycash_model->countGetList();
		
		$this->pagination_editable->initialize($config);
	
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		
		if (isset($_POST['btnSave'])) 
		{
            if (isset($_POST['nmkdpetty']) && !($_POST['nmkdpetty'] == '')) 
			{
	            $this->pettycash_model->setnamapettycash($_POST['nmkdpetty']);
				$this->pettycash_model->setsaldo($_POST['nmlsaldo']);
                $this->pettycash_model->setCreatedBy($this->session->userdata('userid'));
			   	$tanggal=date('Y-m-d H:i:s', strtotime('now'));
				$this->pettycash_model->setCreatedOn($tanggal);
				
				$this->pettycash_model->insert();
				
                redirect('pettycashcontroller');
            } 
			else 
			{
                $dataprofile = array(
					'page_title' => 'Master > Petty Cash',
            		'name' => $this->session->userdata('fullname'),
					'kodepetty' => $this->pettycash_model->getpettyCode(),
					'message' => '<div style="color:red;font-size:9pt;font-weight:bold;">Nama Petty Cash Belum Di Isi </div>',
					'links' => $this->pagination_editable->create_links(),
					'masterpetty' => $this->pettycash_model->getListlimit($config['per_page'],$page)
                );
                $content = array(
                    'content' => 'master/petty_cash/viewpettycash'
                );
                $this->template->load('templates/default', $content, $dataprofile);
            }
        } 
		else 
		{
           $dataprofile = array(
			'page_title' => 'Master > Petty Cash',
			'name' => $this->session->userdata('fullname'),
			'kodepetty' => $this->pettycash_model->getpettyCode(),
			'masterpetty' => $this->pettycash_model->getListlimit(),
			'links' => $this->pagination_editable->create_links($config['per_page'],$page),
			'message' => ''				
			);		
			$content = array(
				'content' => 'master/petty_cash/viewpettycash'
			);
			$this->template->load('templates/default',$content,$dataprofile);
        }
    }
	
    function ubahmasterpetty() {
        $idkdpetty = $this->uri->segment(3);
		$this->pettycash_model->setKodepettycash($idkdpetty);
        if (isset($_POST['btnSave'])) 
		{
			$this->pettycash_model->setKodepettycash($_POST['kdpetty']);
            $this->pettycash_model->setnamapettycash($_POST['nmpetty']);
			$this->pettycash_model->setsaldo($_POST['nmlsaldo']);
 			$this->pettycash_model->setLastUpdateBy($this->session->userdata('userid'));
			$tanggal=date('Y-m-d H:i:s', strtotime('now'));
			$this->pettycash_model->setLastUpdateOn($tanggal);
			
            $this->pettycash_model->ubahmasterpetty();

            redirect('pettycashcontroller');
        } else {
            $this->pettycash_model->setKodepettycash($idkdpetty);
            $dataprofile = array(
				'page_title' => 'Master > Petty Cash',
				'name' => $this->session->userdata('fullname'),
				'links' => $this->pagination_editable->create_links(),
				'masterpetty' => $this->pettycash_model->getkdpettycash()			
			);		
			$content = array(
				'content' => 'master/petty_cash/editpettycash'
			);
			$this->template->load('templates/default',$content,$dataprofile);
        }
    }

    function deletemasterpetty() {
        $kdpetty = $this->uri->segment(3);
        $this->pettycash_model->setKodepettycash($kdpetty);
        $this->pettycash_model->deletemasterpetty();
        redirect('pettycashcontroller');
    }
}